package chapter02;

import java.util.Scanner;

public class Examplesc {
    public static void main(String[] args) {
        double yashua = 8.8; //牙刷价格
        double maojin = 10; //毛巾价格
        double shuibei = 18.8; //水杯价格
        double pingguo = 12.5; //苹果价格
        double xiangjiao = 15.5; //香蕉价格
        System.out.println("-------------黑马小商城-------------");
        System.out.println("1.牙刷的价格为8.8元");
        System.out.println("1.毛巾的价格为10.0元");
        System.out.println("1.水杯的价格为18.8元");
        System.out.println("1.苹果的价格为12.5元");
        System.out.println("1.香蕉的价格为15.5元");
        //循环开始前准备工作
        String xuanZe = "Y";//一种数据类型    存放字符串
        double zongjia = 0;;//总价一般放在循环外部
        Scanner scl = new Scanner(System.in);//用来获取输入
        //不知道用户需要循环几次 可能无限次 使用while 或者 do while
        while (xuanZe.equals("Y")){//Sting不支持 xuanZe == "Y"
            System.out.println("请输入你需要购买的序列号");
            int xuHao = scl.nextInt();//获取输入的序列号
            //判断用户输入的序号 进行不同价格计算
            if (xuHao == 1){
                System.out.println("请输入你要购买牙刷的数量");
                int yaShuaShuLiang = scl.nextInt();
                //加上以前累计购买商品的价格 放入总价
                zongjia = zongjia + yashua * yaShuaShuLiang;
                System.out.println("你购买了牙刷" + yaShuaShuLiang + "只，需要花费" + yashua *yaShuaShuLiang + "元");
            }else if (xuHao == 2){
                System.out.println("请输入你要购买毛巾的数量");
                int maojinShuLiang = scl.nextInt();
                zongjia = zongjia + maojin * maojinShuLiang;
                System.out.println("你购买了毛巾" + maojinShuLiang + "只，需要花费" + maojin * maojinShuLiang + "元");
            }else if (xuHao == 3){
                System.out.println("请输入你要购买水杯的数量");
                int shuibeishuliang = scl.nextInt();
                zongjia = zongjia + shuibei * shuibeishuliang;
                System.out.println("你购买了水杯" + shuibeishuliang + "只，需要花费" + shuibei * shuibeishuliang + "元");
            }else if (xuHao == 4) {
                System.out.println("请输入你要购买苹果的数量");
                int pingguoshuliang = scl.nextInt();
                zongjia = zongjia + pingguo * pingguoshuliang;
                System.out.println("你购买了苹果" + pingguoshuliang + "只，需要花费" + pingguo * pingguoshuliang + "元");
            }else if (xuHao == 5) {
                System.out.println("请输入你要购买香蕉的数量");
                int xiangjiaoshuliang = scl.nextInt();
                zongjia = zongjia + pingguo * xiangjiaoshuliang;
                System.out.println("你购买了香蕉" + xiangjiaoshuliang + "只，需要花费" + xiangjiao * xiangjiaoshuliang + "元");
                //让用户选择是否继续购买
                System.out.println("需要继续购买输入Y，否则输入N");
                xuanZe = scl.next();
            }
        }
    }
}
